home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Learn Microsoft Visual Basic 6.0 Now
/
Learn Microsoft Visual Basic 6.0 Now (Microsoft Press)(X03-58607)(1998).ISO
/
media
/
chap04
/
b04d010.cc2
< prev
next >
Wrap
Text File
|
1998-06-07
|
2KB
|
45 lines
0, In this demonstration you'll see how
2, Visual Basic handles mathematical
4, calculations with advanced operators. The program
7, I've created is an advanced operator
9, tester that uses two variable text boxes,
13, a collection of Option buttons, and a
15, Calculate button to compute a result. The
18, program is running now and to
20, demonstrate it, I'll type a 9 in the first text
22, box and a 2 in the second text box. Then,
29, I'll click the Integer Division button
32, and click the Calculate button to display
34, the result. Visual Basic displays a 4
38, because 9/2=4. Remember in integer
42, division, the remainder of 1 is discarded.
47, When I click the Remainder button and click
49, Calculate, I do see my remainder of 1.
53, And if I click the Exponentiation button
56, and click Calculate, I get 81, the
58, product of 9 squared. Finally, using String
62, Concatenation, I get a result of 92, the
67, textural result of 9 added to 2. Now,
73, let's look at the program code that
75, controls these calculations. I'll stop the
78, program and double-click the Calculate
81, button to open the Command1_Click event
84, procedure. In the event procedure, I
87, declare the first and second variant variables
90, to hold the numbers in the two text
92, boxes. These were the 9 and 2 numbers in
96, the example I just ran. The second and
99, third lines assign those values to the
102, variables. And then I make a test to see if
106, one of the Option buttons has been
108, selected and its Value property been set to
110, True. If this is the case, I use an
113, advanced operator and the two variables to
115, create a result, and I assign that to the
118, Caption property of the Label1 object.
124, You can use this program logic to manage
125, any of the calculations you make in
127, Visual Basic. And you'll learn more about
130, the If...Then decision structure in
131, Chapter 5.
133, END